package com.niuwa.p2p.service.repay.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niuwa.p2p.core.mvc.entity.PageBean;
import com.niuwa.p2p.dao.channel.LoanClaimAuditDao;
import com.niuwa.p2p.dao.repay.RepayDao;
import com.niuwa.p2p.entity.PageQuery;
import com.niuwa.p2p.entity.channel.LoanClaimAudit;
import com.niuwa.p2p.service.repay.IRepayService;
import com.niuwa.p2p.vo.repay.RepayVo;

/**
 * 查询还款信息的Service
 * 
 * @author houdianbo
 * @Date 2015-04-21
 */
@Service
public class RepayServiceImpl implements IRepayService {
	@Autowired
	private RepayDao repayDao;
	@Autowired
	private LoanClaimAuditDao loanClaimAuditDao;

	@Override
	public PageBean<RepayVo> selectRepayByParam(Map<String, Object> paramMap) {
		assert paramMap.get(PageQuery.PAGEQUERY) != null;
		String filterContent = String.valueOf(paramMap.get("filterContent"));
		if (filterContent != null) {
			filterContent = filterContent.trim().replaceAll("%", "\\\\%")
					.replaceAll("_", "\\\\_");
		}
		// 总条数
		int totalCount = repayDao.getRepayCountByParam(paramMap);
		PageBean<RepayVo> page = new PageBean<RepayVo>(totalCount);
		// 当前页
		page.setPage(((PageQuery) paramMap.get(PageQuery.PAGEQUERY)).getPage());
		page.setRows(repayDao.selectRepayByParam(paramMap));
		return page;
	}
	
	@Override
	public PageBean<RepayVo> selectAppRepayByParam(Map<String, Object> paramMap) {
		assert paramMap.get(PageQuery.PAGEQUERY) != null;
		String filterContent = String.valueOf(paramMap.get("filterContent"));
		if (filterContent != null) {
			filterContent = filterContent.trim().replaceAll("%", "\\\\%")
					.replaceAll("_", "\\\\_");
		}
		// 总条数
		int totalCount = repayDao.getAppRepayCountByParam(paramMap);
		PageBean<RepayVo> page = new PageBean<RepayVo>(totalCount);
		// 当前页
		page.setPage(((PageQuery) paramMap.get(PageQuery.PAGEQUERY)).getPage());
		page.setRows(repayDao.selectAppRepayByParam(paramMap));
		return page;
	}

	public void setRepayDao(RepayDao repayDao) {
		this.repayDao = repayDao;
	}

	public void addRepayOverdueRemark(LoanClaimAudit loanClaimAudit) {
		loanClaimAuditDao.insertSelective(loanClaimAudit);
	}
}
